package roles;

import java.util.List;
import java.util.Optional;
import java.util.stream.Collectors;

/**
 * 学生类
 */
public class Student extends User {


    /**
     * 课程ID成绩
     */
    private String  scoreclassid;

    public String getScoreclassid() {
        return scoreclassid;
    }

    public void setScoreclassid(String scoreclassid) {
        this.scoreclassid = scoreclassid;
    }

    public Student(String id, String name, String account, String password, String scoreclassid) {
        super(id, name, account, password);
        this.scoreclassid = scoreclassid;
    }

    public Student() {
    }

    /**
     * 检测当前学生ID是否存在
     */
    public static Student exitStudentId(String id, List<Student> studentList){
        Optional<Student> studentOptional = studentList.stream()
                .filter(student -> student.getId().equals(id))
                .findFirst();
        if(studentOptional.isPresent()){
            return studentOptional.get();
        }
        return null;
    }

    /**
     * 检测当前学生用户名是否存在
     */
    public static Student exitStudentName(String username, List<Student> studentList){
        Optional<Student> studentOptional = studentList.stream()
                .filter(student -> student.getAccount().equals(username))
                .findFirst();
        if(studentOptional.isPresent()){
            return studentOptional.get();
        }
        return null;
    }

    /**
     * 根据课程ID获取学生
     */
    public static List<Student> exitStudentCourseId(String courseId, List<Student> studentList){
        List<Student> studentOptional = studentList.stream()
                .filter(course -> course.getScoreclassid().contains(courseId))
                .collect(Collectors.toList());
        return studentOptional;
    }

}
